/**
 * 菜单JS
 */
angular.module('ddapp.menu', [
])

.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
	$stateProvider
	// 菜单页
	.state('model.ad.shopcar.menu', {
		url: '/menu',
		templateUrl: 'app/menu/menu.html',
		controller: 'MenuController'
	})
	.state('newmenu',{
		url: '/new',
		templateUrl: 'app/menu/newmenu.html',
		controller: 'NewMenuController'
	})
}])

//菜单控制器
.controller('MenuController', ['$rootScope', '$scope', 'MenuService', 'ShoppingCartService', function($rootScope, $scope, MenuService, ShoppingCartService){
	// 获取菜单
	$scope.menu = MenuService.getmenu($scope.rid);
	// 加入购物车
	$scope.addtocart = function(cid, did) {
		ShoppingCartService.addgoods(cid, did);
		$rootScope.buycount = ShoppingCartService.getcount();
		$rootScope.totalprice = ShoppingCartService.gettotalprice();
	}
	// 从购物车移除
	$scope.removefromcart = function(cid, did) {
		ShoppingCartService.removegoods(cid, did);
		$rootScope.buycount = ShoppingCartService.getcount();
		$rootScope.totalprice = ShoppingCartService.gettotalprice();
	}
}])
.controller('NewMenuController',['$scope', '$state', function($scope,$state){
	
}])
